#include <vector>
#include <iostream>
#include<algorithm>
using namespace std;
class Solution {
public:
    int minMoves2(vector<int>& nums) {
        sort(nums.begin(),nums.end());
        int len = nums.size();
        int target = nums[len/2];
        int ans = 0;
        for (int i = 0; i < len; i++)
        {
            ans += abs(nums[i] - target);
        }
        return ans;
    }
};

int main(int argc, char const *argv[])
{
    Solution s;
    vector<int> v = {1,2,4,3};
    int ans  = s.minMoves2(v);
    cout << ans << endl;    
    return 0;
}
